/**
 * 测试弹窗关闭逻辑
 */

// 模拟Page对象
const page = {
  data: {
    adding: false,
    showAddDialog: true
  },

  beforeClose(action) {
    console.log('beforeClose called, action:', action)
    console.log('adding status:', this.data.adding)
    
    // 如果正在添加中，阻止关闭
    if (this.data.adding) {
      console.log('阻止关闭：正在添加中')
      return false
    }
    
    console.log('允许关闭')
    return true
  },

  onCloseAddDialog() {
    console.log('弹窗关闭')
    this.setData({
      showAddDialog: false,
      phone: '',
      adding: false
    })
  },

  setData(data) {
    console.log('setData:', data)
    Object.assign(this.data, data)
  }
}

// 测试场景1：正常关闭
console.log('=== 测试场景1：正常关闭 ===')
page.data.adding = false
const result1 = page.beforeClose('cancel')
console.log('结果:', result1)

// 测试场景2：添加中阻止关闭
console.log('\n=== 测试场景2：添加中阻止关闭 ===')
page.data.adding = true
const result2 = page.beforeClose('cancel')
console.log('结果:', result2)

console.log('\n=== 测试完成 ===') 